<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 300px;
            margin: 0 auto;
            text-align: center;
        }
    </style>
</head>
<body>
    <div>
        <input type="password" id="pwd">
        <input type="button" id="btn" value="隐藏">
    </div>

    <script>
        var pwd = document.getElementById('pwd');
        var btn = document.getElementById('btn');

        btn.onclick = function() {
            pwd.type = this.value === '隐藏' ? 'text' : 'password';
            this.value = this.value === '隐藏' ? '显示' : '隐藏'
            
        }
    </script>

</body>
</html>